import 'package:example/utils/dialog_ext.dart';
import 'package:example/utils/user_handle_manager.dart';
import 'package:example/widget/dialog/sheet_dialog.dart';
import 'package:example/widget/upload_media.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';

import '../../utils/common.dart';


/// 选择图片弹窗
void showImagePickerDialog<T>({
  List<AssetEntity>? selectedAssets,
  RequestType type = RequestType.image,
  MediaActionType actionType = MediaActionType.all,
  maxCount = 1,
  bool defaultCamera=true,
  Function(int type, List<AssetEntity>? files)? confirm,
}) {
  List<String> list;
  switch (actionType) {
    case MediaActionType.camera:
      list = [type == RequestType.image ? "拍照" : "录制视频"];
      break;
    case MediaActionType.photos:
      list = ["从相册中选择"];
      break;
    default:
      list = [type == RequestType.image ? "拍照" : "录制视频", "从相册中选择","取消"];
      break;
  }
  SheetDialog<String>(
    list: list,
    confirm: (item) async {
      Future<List<AssetEntity>?>? result;
      switch (item) {
        case "拍照":
          AssetEntity? file = await UserHandleManager().openCamera(type);
          if (file != null) {
            result = Future.value([file]);
          } else {
            result = Future.value([]);
          }
          result.then((file) => confirm?.call(1, file));
          break;
        case "录制视频":
          if(defaultCamera){
            AssetEntity? file = await UserHandleManager().openCamera(type);
            if (file != null) {
              result = Future.value([file]);
            } else {
              result = Future.value([]);
            }
            result.then((file) => confirm?.call(1, file));
          }else {
            // AssetEntity? file = await videoRecord(type);
            // if (file != null) {
            //   result = Future.value([file]);
            // } else {
            //   result = Future.value([]);
            // }
            // result.then((file) => confirm?.call(1, file));
          }
          break;
        case "从相册中选择":
          result = UserHandleManager().openPhotos(
            selectedAssets: selectedAssets,
            maxCount: maxCount,
            type: type,
          );
          result.then((file) => confirm?.call(2, file));
          break;
      }
    },
  ).show();
}
